package com.yunxi.service.localService.impl.otd;

import com.yunxi.core.util.BeanTools;
import com.yunxi.core.util.DateUtil;
import com.yunxi.otd.pojo.OtdOrderCirScheduleQueryVO;
import com.yunxi.otd.pojo.OtdOrderCirVO;
import com.yunxi.service.localService.otd.OtdProduceCalendarService;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.yunxi.core.service.ServiceImplPlus;
import com.yunxi.dao.otd.OtdOrderCirMonthMapper;
import com.yunxi.model.otd.OtdOrderCirMonth;
import com.yunxi.service.localService.otd.OtdOrderCirMonthService;

/**
 * <p>
 * 月预测CIR 服务实现类
 * </p>
 *
 * @author XUQI
 * @since 2019-10-15
 */
@Service
public class OtdOrderCirMonthServiceImpl extends ServiceImplPlus<OtdOrderCirMonthMapper, OtdOrderCirMonth> implements OtdOrderCirMonthService {

    @Autowired
    @Qualifier("otdProduceCalendarServiceImpl")
    OtdProduceCalendarService calendarService;

    @Override
    public OtdOrderCirVO findCirOrderSchedule(OtdOrderCirScheduleQueryVO queryVO) {
        Map map = BeanTools.bean2map(queryVO);
        String year = queryVO.getYearMonth().substring(0, 4);
        String month = queryVO.getYearMonth().substring(4, 6);
        map.put("days", DateUtil.getDayListByMonth(Integer.valueOf(year), Integer.valueOf(month)));
//        map.put("pageNum", pageNum);
//        map.put("pageSize", pageSize);
//        PageHelperPlus.startPage(pageNum,pageSize);
//        List<Map<String, Object>> list = baseMapper.findCirOrderSchedule(map);
        OtdOrderCirVO data = new OtdOrderCirVO();
        data.setTotal(baseMapper.findCirOrderScheduleCount(map));
        data.setList(baseMapper.findCirOrderSchedule(map));
        return data;
    }

    /**
     * 分页查询月cir分周排程订单
     *
     * @param queryVO 查询VO
     * @return 分页对象
     */
    @Override
    public OtdOrderCirVO findMonthCirWeekly(OtdOrderCirScheduleQueryVO queryVO) {
        Map map = BeanTools.bean2map(queryVO);
        String year = queryVO.getYearMonth().substring(0, 4);
        String month = queryVO.getYearMonth().substring(4, 6);
        map.put("weeks", calendarService.weekListByMonth(year, month));
        OtdOrderCirVO data = new OtdOrderCirVO();
        data.setTotal(baseMapper.findMonthCirWeeklyCount(map));
        data.setList(baseMapper.findMonthCirWeekly(map));
        return data;
    }

    /**
     * 根据年月删除CIR订单
     *
     * @param yearMonths 年月
     */
    @Override
    public void deleteCirOrderByYearMonth(List<String> yearMonths) {
        baseMapper.deleteCirOrderByYearMonth(yearMonths);
    }
}
